<template>
  <gt_guild>
    <template v-slot:nocard v-if="gd.gload == false">
      <div class="nbox1">
        <template v-if="gd.guild?.boss_data?.data?.length >= 1">
          <m_select
            :select="val.select"
            :click="ct.select_click"
            :qs="val.qs"
            :op="val.op"
          >
            <template #sea>
              <el-select
                :style="`min-width: ${cfg.mobile ? 8 : 8}rem`"
                :size="cfg.mobile ? 'small' : ''"
                style="min-width: 12rem"
                :reserve-keyword="false"
                filterable
                placeholder="主控筛选"
                v-model="val.qs.zk"
                @change="ct.select_click"
              >
                <el-option :label="'移除筛选'" :value="''">
                  <div
                    style="
                      display: flex;
                      align-items: center;
                      margin-top: 3px;
                      margin-bottom: 3px;
                    "
                  >
                    <span>移除主控角色筛选</span>
                  </div>
                </el-option>
                <el-option
                  v-for="(item, key) in cfg.role"
                  :label="item.name"
                  :value="item.icon"
                >
                  <div class="el_role_box">
                    <img class="workairole" :src="cfg.function.ava(item.icon)" />
                    <span>　{{ item.name }}</span>
                  </div>
                </el-option>
              </el-select>
            </template>
          </m_select>
          <n-pagination
            :page="Number(val.qs.page)"
            :on-update:page="val.uppage"
            :page-count="val.maxlimit"
            :page-slot="val.pgs"
          />
          <br />
          <template v-if="cfg.mobile == true">
            <component :is="comp.m_report" :val="val" />
          </template>
          <template v-else>
            <component :is="comp.report" :val="val" />
          </template>
        </template>
        <br v-if="cfg.mobile == true" />
        <n-pagination
          :page="Number(val.qs.page)"
          :on-update:page="val.uppage"
          :page-count="val.maxlimit"
          :page-slot="val.pgs"
        /><br /><br />
        <br />
      </div>
    </template>
  </gt_guild>
</template>

<script>
//2024/07/17 猫燐
import { cfg } from "@/cfg/cfg.js";
import { getrole } from "@/cfg/function.js";
import gt_guild from "@/comp/gt_guild.vue";
import m_select from "@/comp/m_select.vue";

export default {
  components: {
    gt_guild,
    m_select,
  },
  setup() {
    const comp = {
      m_report: defineAsyncComponent(() => import("./stat/m_report.vue")),
      report: defineAsyncComponent(() => import("./stat/report.vue")),
    };
    let gd = cfg.guild;
    let val = reactive({
      type: "所有",
      type2: "所有",
      coldw: cfg.mobile == true ? 180 : 280,
      pgwd: cfg.mobile == true ? 45 : 45,
      cols: 1,
      pgs: 7,
      maxlimit: 1,
      uppage: (page) => {
        val.qs.page = page;
        ct.select_click();
      },
      reportdata: [],
      //选择菜单选中
      qs: {
        page: null,
        boss: null,
        sort: null,
        daotype: null,
        level: null,
        round: null,
        player: null,
        role: null,
      },
      //选择菜单列表
      op: {
        boss: [],
        daotype: [
          {
            value: null,
            label: "移除筛选",
          },
          {
            value: "no",
            label: "仅显示完整刀",
          },
          {
            value: "bc",
            label: "仅显示收尾刀",
          },
          {
            value: "end",
            label: "仅显示补偿刀",
          },
          {
            value: "p2",
            label: "60%血以下(P2)",
          },
        ],
        sort: [
          {
            value: "damage",
            label: "伤害排序",
          },
          {
            label: "低伤排序",
            value: "neigui",
          },
          {
            value: "logtime",
            label: "时间排序",
          },
        ],
      },
    });

    val.select = [
      {
        tips: "选择首领",
        val: "boss",
        width: 8,
        mwidth: 8,
      },
      {
        tips: "排序类型",
        val: "sort",
        width: 8,
        mwidth: 8,
      },
      {
        tips: "类型筛选",
        val: "daotype",
        bans2: true,
        width: 8,
        mwidth: 8,
      },
      {
        tips: "等级筛选",
        val: "level",
        width: 8,
        bans2: true,
        mwidth: 8,
      },
      {
        tips: "回合筛选",
        val: "round",
        bans2: true,
        width: 8,
        mwidth: 8,
      },
      {
        tips: "玩家筛选",
        val: "player",
        width: 8,
        mwidth: 8,
      },
    ];

    let ct = reactive({});

    //下拉菜单赛季选择
    ct.select_click = async (dxa) => {
      try {
        if (dxa != null) {
          val.qs.page = 1;
        }
        let res = await cfg.axios.get(`${cfg.url}`, {
          params: {
            t: "v2/get",
            t2: "guild/report",
            gid: gd.guild.gid,
            guild_id: gd.guild.guild_id,
            type: "report",
            season: gd.season,
            ...val.qs,
          },
        });
        res = res.data;
        val.reportdata = res.data;
        val.maxlimit = res.page;
      } catch (error) {
        val.show = false;
        cfg.msg.error(error);
        return false;
      }
    };

    val.cols = parseInt(cfg.sswd / val.coldw);
    val.pgs = parseInt(cfg.sswd / val.pgwd);

    //加载公会初始化
    gd.runfunc = async () => {
      //切换赛季下重置部分设置
      if (val.qs.page != null) {
        val.qs.page = 1;
      }
      if (val.qs.player != null) {
        val.qs.player = null;
      }
      if (val.qs.round != null) {
        val.qs.round = null;
      }
      if (val.qs.level != null) {
        val.qs.level = null;
      }
      if (val.qs.boss != null) {
        val.qs.boss = null;
      }
      if (val.qs.zk != null) {
        val.qs.zk = null;
      }

      //如果是首次打开设置分页
      if (val.qs.page == null) {
        val.qs.page = cfg.route.query.page ?? 1;
      }

      //如果角色数据没有icon重新加载
      if (cfg.role?.[0]?.icon == null) {
        await getrole();
      }

      gd.vuename = "战斗记录";
      val.op.round = [
        {
          value: null,
          label: `移除回合数筛选`,
        },
      ];
      gd.guild?.round?.forEach((item, key) => {
        val.op.round.push({
          value: item,
          label: `回合${item}`,
        });
      });
      val.op.level = [
        {
          value: null,
          label: `移除等级筛选`,
        },
        {
          value: "94-100",
          label: "Level.94-100",
        },
      ];
      val.op.player = [
        {
          value: null,
          label: `移除玩家筛选`,
        },
      ];
      gd.guild?.user_data?.forEach((item, key) => {
        val.op.player.push({
          value: item.user_id,
          label: `${item.user_name}`,
        });
      });
      gd.guild?.level?.forEach((item, key) => {
        val.op.level.push({
          value: item,
          label: `Level.${item}`,
        });
      });
      val.op.boss = [
        {
          value: "all",
          label: `所有首领`,
        },
      ];
      gd.guild.boss_data.data?.forEach((item, key) => {
        val.op.boss.push({
          value: item.boss_name,
          label: `${item.boss_name}`,
        });
      });

      val.qs.boss = "all";
      val.qs.sort = "logtime";
      await ct.select_click();
    };

    //如果触发更新公会
    gd.updfunc = async () => {};

    watch(
      () => cfg.sswd,
      (newWidth, oldWidth) => {
        val.cols = parseInt(cfg.sswd / val.coldw);
        val.pgs = parseInt(cfg.sswd / val.pgwd);
      }
    );

    onMounted(async () => {
      cfg.updateWidth();
    });

    return {
      cfg,
      ct,
      gd,
      val,
      comp,
    };
  },
};
</script>
